﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for BrandDAL
/// </summary>
public class BrandDAL : BaseDAL
{
    public DataSet List(int pageIndex, int pageMax, int brandId)
    {
        DataSet ds = new DataSet();
        string[] uspParaName = new string[] { "@pageIndex", "@pageMax", "@brandId" };
        object[] uspParaValue = new object[] { pageIndex, pageMax, brandId };
        string uspName = "MiT_usp_brand_listbrand";

        ds = base.RunProcedure(uspParaName, uspParaValue, uspName);
        return ds;
    }
    public DataSet Detail(int brandId)
    {
        DataSet ds = new DataSet();

        string query = string.Format("select * from MiT_Brands where BrandId = {0} and IsActive = 1;", brandId.ToString());
        ds = base.RunQuery(query);
        
        return ds;
    }
    public DataSet Insert(string brandName, string logo, int isActive)
    {
        DataSet ds = new DataSet();
        string query = string.Format("insert into MiT_brands (BrandName, BrandLogo, isActive) values (N'{0}','{1}',{2});", brandName, logo, isActive);
        ds = base.RunQuery(query);
        return ds;
    }
    public DataSet Update(int brandid, string brandName, int isActive, string urlLogo)
    {
        DataSet ds = new DataSet();
        string query = string.Format("update MiT_brands set brandName=N'{0}', IsActive={1}, BrandLogo='{2}' where brandid={3};select {3} as brandid", brandName, isActive.ToString(), urlLogo, brandid);
        ds = base.RunQuery(query);
        return ds;
    }
    public DataSet UpdateStatusActive(int brandid, int isActive)
    {
        DataSet ds = new DataSet();
        string query = string.Format("update MiT_brands set IsActive={0} where brandid={1}; select {1} as BrandId;", isActive, brandid);
        ds = base.RunQuery(query);
        return ds;
    }
    public string InsertBrandProduct(int brandId, int productId)
    {
        string ret = "";
        DataSet ds = new DataSet();
        string query = string.Format("insert into brand_products(brandid, productid) value({0},{1});select 1", brandId, productId);
        ds = base.RunQuery(query);
        return ret;
    }
}